<? require_once("sitemap.php"); ?>
<?
$action="start";

if (!empty($_POST['action']))
{
	$action = $_POST['action'];
}
?>
<html>
	<title><? echo (":" . $HTTP_SERVER_VARS['REMOTE_USER'] . ": ". $Botname ); ?>'s EL-BOT Alt Adverts Management</title>
<body>
	<h1><? echo ($Botname); ?>'s EL-BOT Alt Adverts Management</h1>
		
	<h2>Alt Adverts - Add:</h2>
	<form method="post" action="<? echo ($_SERVER['PHP_SELF']); ?>">
	<input type="hidden" name="action" value="add">
	<table border=0 cellpadding="0" cellspacing="0"><tr><td><input type="text" size="140" name="adverttext" value=""></td><td><input type="submit" name="submit" value="ADD"></td></tr></table>
	</form>

	<form method="post" action="<? echo ($_SERVER['PHP_SELF']); ?>"><input type="submit" name="submit" value="RELOAD"><input type="hidden" name="action" value="refresh"></form>
	<?
	if ($action=="remove")
	{
		dumppost($HTTP_SERVER_VARS['REMOTE_USER']);
		$id=intval(mysql_real_escape_string($_POST['id']));
		$sql = "DELETE FROM otheradverts WHERE id='$id';";
		$result = mysql_query($sql,$db);
	}
	if ($action=="update")
	{
		dumppost($HTTP_SERVER_VARS['REMOTE_USER']);						
		$id=intval(mysql_real_escape_string($_POST['id']));
		$adverttext=(mysql_real_escape_string($_POST['adverttext']));
		$channel=intval(mysql_real_escape_string($_POST['channel']));
		if (empty($_POST['disabled'])) {$disabled = 0;} else {$disabled = 1;} 

		$sql = "UPDATE adverts SET adverttext='$adverttext', channel='$channel', disabled='$disabled' WHERE adverts.id='$id';";
		$result = mysql_query($sql,$db);
	}
	if ($action=="add")
	{
		dumppost($HTTP_SERVER_VARS['REMOTE_USER']);						
		$id=intval(mysql_real_escape_string($_POST['id']));
		$adverttext=(mysql_real_escape_string($_POST['adverttext']));
		$channel=intval(mysql_real_escape_string($_POST['channel']));
		$sql = "INSERT INTO otheradverts (text,channel,disabled,botid) VALUES ('$adverttext',,'0','$botid');";
		$result = mysql_query($sql,$db);
	}
	?>
<h2>Alt Adverts - Edit:</h2>
	<table border="1" cellpadding="0" cellspacing="0">
		<tr>
			<td>id</td>
			<td>disabled</td>
			<td>Advert Text</td>
			<td>Channel</td>
			<td>Functions</td>
		</tr>
		<?php
		$result = mysql_query("SELECT id, disabled, text, channel FROM otheradverts WHERE botid='" . $botid . "';",$db);

		while ($myrow = mysql_fetch_row($result))
		{
		?>
		<tr>
			<form method="post" action="<?echo ($_SERVER['PHP_SELF']); ?>">
				<input type="hidden" name="action" value="update">
				<input type="hidden" name="id" value="<?echo ($myrow[0])?>">
				<td><?echo ($myrow[0])?></td>
				<td><input type="checkbox" name="disabled" <? if ($myrow[1]==1) {echo ("checked");} ?>></td>
				<td><input type="text" size="140" name="adverttext" value="<?echo stripslashes($myrow[2])?>"></td>
				<td><input type="text" size="5" name="channel" value="<?echo stripslashes($myrow[3])?>"></td>
				<td><input type="submit" name="submit" value="UPDATE">
			</form>
			<form method="post" action="<? echo ($_SERVER['PHP_SELF']); ?>">
				<input type="hidden" name="action" value="remove">
				<input type="hidden" name="id" value="<?echo ($myrow[0])?>">
				<input type="submit" name="submit" value="REMOVE">
			</form>
			</td>
		</tr>
		<?
		}
		?>
	</table>
</body>
</html>
